package br.com.gfkauer.model.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import br.com.gfkauer.model.enums.Role;

@Entity
@Table(name="USERS")
@NamedQuery(name="User.findUserByEmail", query="select u from User u where u.email = :email")
public class User implements Serializable{
	private static final long serialVersionUID = 1L;
	
	public static final String FIND_BY_EMAIL = "User.findUserByEmail";
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private int id;
	
	@Column(unique=true)
	private String email;
	private String password;
	private String name;
	@Enumerated(EnumType.STRING)
	private Role role;

	// Getters e Setters
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Role getRole() {
		return role;
	}
	public void setRole(Role role) {
		this.role = role;
	}
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	public static String getFindByEmail() {
		return FIND_BY_EMAIL;
	}
	
	public boolean isAdmin(){
		return Role.ADMIN.equals(role);
	}
	
	public boolean isUser(){
		return Role.USER.equals(role);
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof User){
			User user = (User) obj;
			return user.getId() == id;
		}
		
		return false;
		
	}
	
	@Override
	public int hashCode() {
		return getId();
	}
	
	
	
}
